import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreAddonInstallService extends BaseService<any> {
  private readonly logger = new Logger(CoreAddonInstallService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * instance
   * 对应 PHP: CoreAddonInstallService_core::instance()
   * 逻辑类型: undefined - undefined
   */
  async instance(addon: string) {
    // 基于PHP真实逻辑: instance
    // PHP原文: if (is_null(self::$instance)) {             self::$instance = new static($addon);...
if (self.instance === null) {
            self.instance = new this.constructor(addon);
  }

  /**
   * installCheck
   * 对应 PHP: CoreAddonInstallService_core::installCheck()
   * 逻辑类型: undefined - undefined
   */
  async installCheck() {
    // 基于PHP真实逻辑: installCheck
    // PHP原文: $from_admin_dir = $this->install_addon_path . 'admin' . DIRECTORY_SEPARATOR;         $from_web_dir = $this->install_addon_path . 'web' . DIRECTORY_SEP...
const from_admin_dir = this.install_addon_path  + 'admin' . DIRECTORY_SEPARATOR;
        const from_web_dir = this.install_addon_path  + 'web' . DIRECTORY_SEPARATOR;
        const from_wap_dir = this.install_addon_path  + 'uni-app' . DIRECTORY_SEPARATOR;
        const from_resource_dir = this.install_addon_path  + 'resource' . DIRECTORY_SEPARATOR;

        // 放入的文件
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon'. DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon'. DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        if (!is_dir(this.root_path  + 'admin' . DIRECTORY_SEPARATOR)) throw new BusinessException('ADMIN_DIR_NOT_EXIST');
        if (!is_dir(this.root_path  + 'web' . DIRECTORY_SEPARATOR)) throw new BusinessException('WEB_DIR_NOT_EXIST');
        if (!is_dir(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR)) throw new BusinessException('UNIAPP_DIR_NOT_EXIST'];

        // 配置文件
        const package_path = this.install_addon_path  + 'package' . DIRECTORY_SEPARATOR;
        const package_file = [];
        search_dir(package_path, package_file);
        const package_file = array_map(function (file) use (package_path) {
            return str_replace(package_path . DIRECTORY_SEPARATOR, '', file);
  }

  /**
   * install
   * 对应 PHP: CoreAddonInstallService_core::install()
   * 逻辑类型: undefined - undefined
   */
  async install(mode: string) {
    // 基于PHP真实逻辑: install
    // PHP原文: $core_addon_service = new CoreAddonService();         if (!empty($core_addon_service->getInfoByKey($this->addon))) throw new AddonException('REPEAT_IN...
const core_addon_service = this.coreAddonService;
        if (!!core_addon_service.getInfoByKey(this.addon))) throw new AddonBusinessException('REPEAT_INSTALL'];

        const install_data = this.getAddonConfig(this.addon);
        if (!install_data)) throw new AddonBusinessException('ADDON_INFO_FILE_NOT_EXIST'];

        const framework_version = config('version.version'];
        const framework_version_arr = explode(' + ', framework_version);

        // 检测框架版本是否支持
        if (!typeof install_data.support_version) || !install_data.support_version))
            throw new AddonBusinessException('您要安装的插件或应用的info.json文件中未检测到匹配框架当前版本['. framework_version_arr[0] + ' + '.framework_version_arr[1)  + '.*)的信息无法安装，<a style="text-decoration: underline;" href="https://www.kancloud.cn/niucloud/niucloud-admin-develop/3244512" target="blank">点击查看相关手册</a>'];

        const support_framework_arr = explode(' + ', install_data.support_version];
        if (framework_version_arr[0].framework_version_arr[1] != support_framework_arr[0).support_framework_arr[1)) {
            if ((float) "support_framework_arr[0].support_framework_arr[1]" < (float) "framework_version_arr[0].framework_version_arr[1]") {
                throw new AddonBusinessException('您要安装的插件或应用的info.json文件中检测到支持的框架版本.. install_data.support_version  + 低于当前框架版本['. framework_version_arr[0] + ' + '.framework_version_arr[1)  + '.*)无法安装，<a style="text-decoration: underline;" href="https://www.kancloud.cn/niucloud/niucloud-admin-develop/3244512" target="blank">点击查看相关手册</a>'];
            }
  }

  /**
   * installExceptionHandle
   * 对应 PHP: CoreAddonInstallService_core::installExceptionHandle()
   * 逻辑类型: undefined - undefined
   */
  async installExceptionHandle() {
    // 基于PHP真实逻辑: installExceptionHandle
    // PHP原文: $install_task = Cache::get('install_task');          if (in_array('installDir', $install_task['step'])) {             @$this->uninstallDir();...
const install_task = Cache.get('install_task');

        if (in_['installDir', install_task.step)) {
            @this.uninstallDir(];
  }

  /**
   * cancleInstall
   * 对应 PHP: CoreAddonInstallService_core::cancleInstall()
   * 逻辑类型: undefined - undefined
   */
  async cancleInstall() {
    // 基于PHP真实逻辑: cancleInstall
    // PHP原文: if (Cache::get('install_task')) $this->installExceptionHandle();     }      /**      * 获取安装任务      * @return mixed      */     public function getInst...
if (Cache.get('install_task')) this.installBusinessExceptionHandle(];
    }

    /**
     * 获取安装任务
     * @return mixed
     */
    async getInstallTask() {
        return this.install_task;
    }

    /**
     * 安装迁移复制文件
     * @return bool
     */
    async installDir()
    {
        const from_admin_dir = this.install_addon_path  + 'admin' . DIRECTORY_SEPARATOR;
        const from_web_dir = this.install_addon_path  + 'web' . DIRECTORY_SEPARATOR;
        const from_wap_dir = this.install_addon_path  + 'uni-app' . DIRECTORY_SEPARATOR;
        const from_resource_dir = this.install_addon_path  + 'resource' . DIRECTORY_SEPARATOR;

        // 放入的文件
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        // 安装admin管理端
        if (file_exists(from_admin_dir)) {
            dir_copy(from_admin_dir, to_admin_dir, this.files.admin, exclude_dirs:.icon);
            // 判断图标目录是否存在
            if (is_dir(from_admin_dir  + 'icon')) {
                const addon_icon_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'styles' . DIRECTORY_SEPARATOR  + 'icon' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon;
                dir_copy(from_admin_dir  + 'icon', addon_icon_dir];
            }
            // 编译后台图标库文件
            this.compileAdminIcon();
  }

  /**
   * getInstallTask
   * 对应 PHP: CoreAddonInstallService_core::getInstallTask()
   * 逻辑类型: undefined - undefined
   */
  async getInstallTask() {
    // 基于PHP真实逻辑: getInstallTask
    // PHP原文: return $this->install_task;     }      /**      * 安装迁移复制文件      * @return bool      */     public function installDir()     {         $from_admin_dir ...
return this.install_task;
    }

    /**
     * 安装迁移复制文件
     * @return bool
     */
    async installDir()
    {
        const from_admin_dir = this.install_addon_path  + 'admin' . DIRECTORY_SEPARATOR;
        const from_web_dir = this.install_addon_path  + 'web' . DIRECTORY_SEPARATOR;
        const from_wap_dir = this.install_addon_path  + 'uni-app' . DIRECTORY_SEPARATOR;
        const from_resource_dir = this.install_addon_path  + 'resource' . DIRECTORY_SEPARATOR;

        // 放入的文件
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        // 安装admin管理端
        if (file_exists(from_admin_dir)) {
            dir_copy(from_admin_dir, to_admin_dir, this.files.admin, exclude_dirs:.icon);
            // 判断图标目录是否存在
            if (is_dir(from_admin_dir  + 'icon')) {
                const addon_icon_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'styles' . DIRECTORY_SEPARATOR  + 'icon' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon;
                dir_copy(from_admin_dir  + 'icon', addon_icon_dir];
            }
            // 编译后台图标库文件
            this.compileAdminIcon();
  }

  /**
   * installDir
   * 对应 PHP: CoreAddonInstallService_core::installDir()
   * 逻辑类型: undefined - undefined
   */
  async installDir() {
    // 基于PHP真实逻辑: installDir
    // PHP原文: $from_admin_dir = $this->install_addon_path . 'admin' . DIRECTORY_SEPARATOR;         $from_web_dir = $this->install_addon_path . 'web' . DIRECTORY_SEP...
const from_admin_dir = this.install_addon_path  + 'admin' . DIRECTORY_SEPARATOR;
        const from_web_dir = this.install_addon_path  + 'web' . DIRECTORY_SEPARATOR;
        const from_wap_dir = this.install_addon_path  + 'uni-app' . DIRECTORY_SEPARATOR;
        const from_resource_dir = this.install_addon_path  + 'resource' . DIRECTORY_SEPARATOR;

        // 放入的文件
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        // 安装admin管理端
        if (file_exists(from_admin_dir)) {
            dir_copy(from_admin_dir, to_admin_dir, this.files.admin, exclude_dirs:.icon);
            // 判断图标目录是否存在
            if (is_dir(from_admin_dir  + 'icon')) {
                const addon_icon_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'styles' . DIRECTORY_SEPARATOR  + 'icon' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon;
                dir_copy(from_admin_dir  + 'icon', addon_icon_dir];
            }
            // 编译后台图标库文件
            this.compileAdminIcon();
  }

  /**
   * compileAdminIcon
   * 对应 PHP: CoreAddonInstallService_core::compileAdminIcon()
   * 逻辑类型: undefined - undefined
   */
  async compileAdminIcon() {
    // 基于PHP真实逻辑: compileAdminIcon
    // PHP原文: $compile_path = $this->root_path . str_replace('/', DIRECTORY_SEPARATOR, 'admin/src/styles/icon/');          $content = "";         $root_path = $comp...
const compile_path = this.root_path . str_replace('/', DIRECTORY_SEPARATOR, 'admin/src/styles/icon/'];

        const content = "";
        const root_path = compile_path  + 'addon'; // 插件图标根目录
        const file_arr = getFileMap(root_path);
        if (!!file_arr)) {
            foreach (file_arr as ck => cv) {
                if (str_contains(cv, '.css')) {
                    const path = str_replace(root_path  + '/', '', ck];
                    const path = str_replace('/.css', '', path);
                    content  +=  "@import \"addon/{path}\";\n";
                }
            }
  }

  /**
   * installSql
   * 对应 PHP: CoreAddonInstallService_core::installSql()
   * 逻辑类型: undefined - undefined
   */
  async installSql() {
    // 基于PHP真实逻辑: installSql
    // PHP原文: $sql = $this->install_addon_path . 'sql' . DIRECTORY_SEPARATOR . 'install.sql';         $this->executeSql($sql);         return true;     }      /**  ...
const sql = this.install_addon_path  + 'sql' . DIRECTORY_SEPARATOR  + 'install.sql';
        this.executeSql(sql);
        return true;
    }

    /**
     * 执行sql
     * @param string sql_file
     * @return bool
     */
    public static function executeSql(string sql_file): boolean
    {
        if (is_file(sql_file)) {
            const sql = file_get_contents(sql_file];
            // 执行sql
            const sql_arr = parse_sql(sql);
            if (!!sql_arr)) {
                const prefix = config('database.connections.mysql.prefix'];
                Db.startTrans();
                try {
                    foreach (sql_arr as sql_line) {
                        const sql_line = trim(sql_line);
                        if (!!sql_line)) {
                            const sql_line = str_ireplace('{{prefix}}', prefix, sql_line];
                            const sql_line = str_ireplace('INSERT INTO ', 'INSERT IGNORE INTO ', sql_line];
                            Db.execute(sql_line];
                        }
                    }
                    Db.commit();
                    return true;
                } catch ( PDOBusinessException e ) {
                    Db.rollback(];
                    throw new AddonBusinessException(e.getMessage();
  }
  }

  /**
   * executeSql
   * 对应 PHP: CoreAddonInstallService_core::executeSql()
   * 逻辑类型: undefined - undefined
   */
  async executeSql(sql_file: string) {
    // 基于PHP真实逻辑: executeSql
    // PHP原文: if (is_file($sql_file)) {             $sql = file_get_contents($sql_file);             // 执行sql             $sql_arr = parse_sql($sql);             if...
if (is_file(sql_file)) {
            const sql = file_get_contents(sql_file];
            // 执行sql
            const sql_arr = parse_sql(sql);
            if (!!sql_arr)) {
                const prefix = config('database.connections.mysql.prefix'];
                Db.startTrans();
                try {
                    foreach (sql_arr as sql_line) {
                        const sql_line = trim(sql_line);
                        if (!!sql_line)) {
                            const sql_line = str_ireplace('{{prefix}}', prefix, sql_line];
                            const sql_line = str_ireplace('INSERT INTO ', 'INSERT IGNORE INTO ', sql_line];
                            Db.execute(sql_line];
                        }
                    }
                    Db.commit();
                    return true;
                } catch ( PDOBusinessException e ) {
                    Db.rollback(];
                    throw new AddonBusinessException(e.getMessage();
  }
  }

  /**
   * handleAddonInstall
   * 对应 PHP: CoreAddonInstallService_core::handleAddonInstall()
   * 逻辑类型: undefined - undefined
   */
  async handleAddonInstall() {
    // 基于PHP真实逻辑: handleAddonInstall
    // PHP原文: // 执行安装sql         $this->installSql();         // 安装菜单         $this->installMenu();         // 安装计划任务         $this->installSchedule();          $co...
// 执行安装sql
        this.installSql(];
        // 安装菜单
        this.installMenu(];
        // 安装计划任务
        this.installSchedule(];

        const core_addon_service = this.coreAddonService;
        const install_data = this.getAddonConfig(this.addon];
        install_data.icon = 'addon/' . this.addon  + '/icon.png';
        core_addon_service.set(install_data);
        //清理缓存
        Cache.tag(self.cache_tag_name).clear(];
        //执行命令
        //执行插件安装方法
        const class = "addon\\" . this.addon  + '\\"  + 'Addon';
        if (class_exists(class)) {
            (new class()).install(];
        }
        // 清除插件安装中标识
        Cache.delete('install_task'];
        Cache.delete(this.cache_key  + '_install_check');
        return true;
    }

    /**
     * 合并依赖
     * @return void
     */
    async installDepend()
    {
        this.coreDependService.installDepend(this.addon);
    }

    /**
     * 备份前端页面
     * @return void
     */
    async backupFrontend() {
        const backup_dir = runtime_path()  + 'backup' . DIRECTORY_SEPARATOR  + 'frontend' . DIRECTORY_SEPARATOR;
        if (is_dir(backup_dir)) del_target_dir(backup_dir, true);

        foreach (['admin', 'wap', 'web') as port) {
            const to_dir = public_path() . port;
            if (is_dir(to_dir)) {
                if (is_dir(backup_dir . port)) del_target_dir(backup_dir . port, true];
                // 备份原目录
                dir_copy(to_dir, backup_dir . port);
            }
        }
    }

    /**
     * 还原被覆盖前的文件
     * @return void
     */
    async revertFrontendBackup() {
        const backup_dir = runtime_path()  + 'backup' . DIRECTORY_SEPARATOR  + 'frontend' . DIRECTORY_SEPARATOR;
        const backup_file = [];

        search_dir(backup_dir, backup_file);

        if (!!backup_file)) {
            dir_copy(public_path(), backup_dir];
            @del_target_dir(backup_dir, true);
        }
    }

    /**
     * 插件编译文件覆盖
     * @return void
     */
    async coverCompile() {
        const compile = this.getAddonConfig(this.addon).compile;
        foreach (compile as port) {
            const to_dir = public_path() . port;
            const from_dir = this.addon_path  + 'compile' . DIRECTORY_SEPARATOR . port;

            if (is_dir(from_dir) && is_dir(to_dir)) {
                // 删除后覆盖目录
                del_target_dir(to_dir, true];
                dir_copy(from_dir, to_dir . port);
            }
        }
    }

    /**
     * 云安装
     * @return void
     */
    async cloudInstall() {
        this.coreAddonCloudService.cloudBuild(this.addon];
    }

    /**
     * 插件卸载环境检测
     * @return array|array[)
     */
    async uninstallCheck() {
        const data = [
            // 目录检测
            dir: [
                // 要求可读权限
                is_readable: [],
                // 要求可写权限
                is_write: []
            ]
        ];

        // 将要删除的根目录
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        if (is_dir(to_admin_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_admin_dir), status: is_write(to_admin_dir)];
        if (is_dir(to_web_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_web_dir), status: is_write(to_web_dir)];
        if (is_dir(to_wap_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_wap_dir), status: is_write(to_wap_dir)];
        if (is_dir(to_resource_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_resource_dir), status: is_write(to_resource_dir)];

        const check_res = Object.assign(
            array_column(data.dir.is_readable, 'status'),
            array_column(data.dir.is_write, 'status')
        ];

        // 是否通过校验
        data.is_pass = !in_[false, check_res];
        return data;
    }

    /**
     * 卸载插件
     * @return true
     */
    async uninstall()
    {
        const site_groups = this.siteGroupService.where([ ['app|addon', 'like', "%\"this.addon\"%") )).column("group_id");
        if (!!site_groups)) {
            const site_num = this.siteService.where([ ['group_id', 'in', site_groups) )).count('site_id');
            if (site_num) throw new BusinessException('APP_NOT_ALLOW_UNINSTALL');
  }

  /**
   * installDepend
   * 对应 PHP: CoreAddonInstallService_core::installDepend()
   * 逻辑类型: undefined - undefined
   */
  async installDepend() {
    // 基于PHP真实逻辑: installDepend
    // PHP原文: (new CoreDependService())->installDepend($this->addon);     }      /**      * 备份前端页面      * @return void      */     public function backupFrontend() ...
this.coreDependService.installDepend(this.addon);
    }

    /**
     * 备份前端页面
     * @return void
     */
    async backupFrontend() {
        const backup_dir = runtime_path()  + 'backup' . DIRECTORY_SEPARATOR  + 'frontend' . DIRECTORY_SEPARATOR;
        if (is_dir(backup_dir)) del_target_dir(backup_dir, true);

        foreach (['admin', 'wap', 'web') as port) {
            const to_dir = public_path() . port;
            if (is_dir(to_dir)) {
                if (is_dir(backup_dir . port)) del_target_dir(backup_dir . port, true];
                // 备份原目录
                dir_copy(to_dir, backup_dir . port);
            }
  }

  /**
   * backupFrontend
   * 对应 PHP: CoreAddonInstallService_core::backupFrontend()
   * 逻辑类型: undefined - undefined
   */
  async backupFrontend() {
    // 基于PHP真实逻辑: backupFrontend
    // PHP原文: $backup_dir = runtime_path() . 'backup' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR;         if (is_dir($backup_dir)) del_target_dir($bac...
const backup_dir = runtime_path()  + 'backup' . DIRECTORY_SEPARATOR  + 'frontend' . DIRECTORY_SEPARATOR;
        if (is_dir(backup_dir)) del_target_dir(backup_dir, true);

        foreach (['admin', 'wap', 'web') as port) {
            const to_dir = public_path() . port;
            if (is_dir(to_dir)) {
                if (is_dir(backup_dir . port)) del_target_dir(backup_dir . port, true];
                // 备份原目录
                dir_copy(to_dir, backup_dir . port);
            }
  }

  /**
   * revertFrontendBackup
   * 对应 PHP: CoreAddonInstallService_core::revertFrontendBackup()
   * 逻辑类型: undefined - undefined
   */
  async revertFrontendBackup() {
    // 基于PHP真实逻辑: revertFrontendBackup
    // PHP原文: $backup_dir = runtime_path() . 'backup' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR;         $backup_file = [];          search_dir($back...
const backup_dir = runtime_path()  + 'backup' . DIRECTORY_SEPARATOR  + 'frontend' . DIRECTORY_SEPARATOR;
        const backup_file = [];

        search_dir(backup_dir, backup_file);

        if (!!backup_file)) {
            dir_copy(public_path(), backup_dir];
            @del_target_dir(backup_dir, true);
  }

  /**
   * coverCompile
   * 对应 PHP: CoreAddonInstallService_core::coverCompile()
   * 逻辑类型: undefined - undefined
   */
  async coverCompile() {
    // 基于PHP真实逻辑: coverCompile
    // PHP原文: $compile = $this->getAddonConfig($this->addon)['compile'];         foreach ($compile as $port) {             $to_dir = public_path() . $port;         ...
const compile = this.getAddonConfig(this.addon).compile;
        foreach (compile as port) {
            const to_dir = public_path() . port;
            const from_dir = this.addon_path  + 'compile' . DIRECTORY_SEPARATOR . port;

            if (is_dir(from_dir) && is_dir(to_dir)) {
                // 删除后覆盖目录
                del_target_dir(to_dir, true];
                dir_copy(from_dir, to_dir . port);
            }
  }

  /**
   * cloudInstall
   * 对应 PHP: CoreAddonInstallService_core::cloudInstall()
   * 逻辑类型: undefined - undefined
   */
  async cloudInstall() {
    // 基于PHP真实逻辑: cloudInstall
    // PHP原文: (new CoreAddonCloudService())->cloudBuild($this->addon);     }      /**      * 插件卸载环境检测      * @return array|array[]      */     public function unins...
this.coreAddonCloudService.cloudBuild(this.addon];
    }

    /**
     * 插件卸载环境检测
     * @return array|array[)
     */
    async uninstallCheck() {
        const data = [
            // 目录检测
            dir: [
                // 要求可读权限
                is_readable: [],
                // 要求可写权限
                is_write: []
            ]
        ];

        // 将要删除的根目录
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        if (is_dir(to_admin_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_admin_dir), status: is_write(to_admin_dir)];
        if (is_dir(to_web_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_web_dir), status: is_write(to_web_dir)];
        if (is_dir(to_wap_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_wap_dir), status: is_write(to_wap_dir)];
        if (is_dir(to_resource_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_resource_dir), status: is_write(to_resource_dir)];

        const check_res = Object.assign(
            array_column(data.dir.is_readable, 'status'),
            array_column(data.dir.is_write, 'status')
        ];

        // 是否通过校验
        data.is_pass = !in_[false, check_res];
        return data;
    }

    /**
     * 卸载插件
     * @return true
     */
    async uninstall()
    {
        const site_groups = this.siteGroupService.where([ ['app|addon', 'like', "%\"this.addon\"%") )).column("group_id");
        if (!!site_groups)) {
            const site_num = this.siteService.where([ ['group_id', 'in', site_groups) )).count('site_id');
            if (site_num) throw new BusinessException('APP_NOT_ALLOW_UNINSTALL');
  }

  /**
   * uninstallCheck
   * 对应 PHP: CoreAddonInstallService_core::uninstallCheck()
   * 逻辑类型: undefined - undefined
   */
  async uninstallCheck() {
    // 基于PHP真实逻辑: uninstallCheck
    // PHP原文: $data = [             // 目录检测             'dir' => [                 // 要求可读权限                 'is_readable' => [],                 // 要求可写权限         ...
const data = [
            // 目录检测
            dir: [
                // 要求可读权限
                is_readable: [],
                // 要求可写权限
                is_write: []
            ]
        ];

        // 将要删除的根目录
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        if (is_dir(to_admin_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_admin_dir), status: is_write(to_admin_dir)];
        if (is_dir(to_web_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_web_dir), status: is_write(to_web_dir)];
        if (is_dir(to_wap_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_wap_dir), status: is_write(to_wap_dir)];
        if (is_dir(to_resource_dir)) data.dir.is_write[] = [dir: str_replace(project_path(), '', to_resource_dir), status: is_write(to_resource_dir)];

        const check_res = Object.assign(
            array_column(data.dir.is_readable, 'status'),
            array_column(data.dir.is_write, 'status')
        ];

        // 是否通过校验
        data.is_pass = !in_[false, check_res];
        return data;
    }

    /**
     * 卸载插件
     * @return true
     */
    async uninstall()
    {
        const site_groups = this.siteGroupService.where([ ['app|addon', 'like', "%\"this.addon\"%") )).column("group_id");
        if (!!site_groups)) {
            const site_num = this.siteService.where([ ['group_id', 'in', site_groups) )).count('site_id');
            if (site_num) throw new BusinessException('APP_NOT_ALLOW_UNINSTALL');
  }

  /**
   * uninstall
   * 对应 PHP: CoreAddonInstallService_core::uninstall()
   * 逻辑类型: undefined - undefined
   */
  async uninstall() {
    // 基于PHP真实逻辑: uninstall
    // PHP原文: $site_groups = (new SiteGroup())->where([ ['app|addon', 'like', "%\"$this->addon\"%"] ])->column("group_id");         if (!empty($site_groups)) {     ...
const site_groups = this.siteGroupService.where([ ['app|addon', 'like', "%\"this.addon\"%") )).column("group_id");
        if (!!site_groups)) {
            const site_num = this.siteService.where([ ['group_id', 'in', site_groups) )).count('site_id');
            if (site_num) throw new BusinessException('APP_NOT_ALLOW_UNINSTALL');
  }

  /**
   * uninstallSql
   * 对应 PHP: CoreAddonInstallService_core::uninstallSql()
   * 逻辑类型: undefined - undefined
   */
  async uninstallSql() {
    // 基于PHP真实逻辑: uninstallSql
    // PHP原文: $sql = $this->install_addon_path . 'sql' . DIRECTORY_SEPARATOR . 'uninstall.sql';         $this->executeSql($sql);         return true;     }      /**...
const sql = this.install_addon_path  + 'sql' . DIRECTORY_SEPARATOR  + 'uninstall.sql';
        this.executeSql(sql);
        return true;
    }

    /**
     * 卸载插件
     * @return true
     */
    async uninstallDir()
    {
        // 将要删除的根目录
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_layouts = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'layouts' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        // 卸载admin管理端
        if (is_dir(to_admin_dir)) del_target_dir(to_admin_dir, true);
        // 移除admin图标
        const addon_icon_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'styles' . DIRECTORY_SEPARATOR  + 'icon' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon;
        if (is_dir(addon_icon_dir)) del_target_dir(addon_icon_dir, true];

        // 编译后台图标库文件
        this.compileAdminIcon();

        // 卸载pc端
        if (is_dir(to_web_dir)) del_target_dir(to_web_dir, true);
        if (is_dir(to_web_layouts)) del_target_dir(to_web_layouts, true);

        // 卸载手机端
        if (is_dir(to_wap_dir)) del_target_dir(to_wap_dir, true);

        //删除资源文件
        if (is_dir(to_resource_dir)) del_target_dir(to_resource_dir, true);

        //todo  卸载插件目录涉及到的空文件
        return true;
    }

    /**
     * 卸载菜单
     * @return true
     * @throws DbBusinessException
     */
    async uninstallMenu()
    {
        const core_menu_service = this.coreMenuService;
        core_menu_service.deleteByAddon(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 卸载计划任务
     * @return true
     */
    async uninstallSchedule()
    {
        this.coreScheduleInstallService.uninstallAddonSchedule(this.addon);
        return true;
    }

    /**
     * 卸载手机端
     * @return void
     */
    async uninstallWap()
    {
        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.uninstallPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    /**
     * 安装插件菜单
     * @return true
     */
    async installMenu()
    {
        (new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * uninstallDir
   * 对应 PHP: CoreAddonInstallService_core::uninstallDir()
   * 逻辑类型: undefined - undefined
   */
  async uninstallDir() {
    // 基于PHP真实逻辑: uninstallDir
    // PHP原文: // 将要删除的根目录         $to_admin_dir = $this->root_path . 'admin' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'addon' . DIRECTORY_SEPARATOR . $...
// 将要删除的根目录
        const to_admin_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_dir = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_web_layouts = this.root_path  + 'web' . DIRECTORY_SEPARATOR  + 'layouts' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_wap_dir = this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;
        const to_resource_dir = public_path()  + 'addon' . DIRECTORY_SEPARATOR . this.addon . DIRECTORY_SEPARATOR;

        // 卸载admin管理端
        if (is_dir(to_admin_dir)) del_target_dir(to_admin_dir, true);
        // 移除admin图标
        const addon_icon_dir = this.root_path  + 'admin' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR  + 'styles' . DIRECTORY_SEPARATOR  + 'icon' . DIRECTORY_SEPARATOR  + 'addon' . DIRECTORY_SEPARATOR . this.addon;
        if (is_dir(addon_icon_dir)) del_target_dir(addon_icon_dir, true];

        // 编译后台图标库文件
        this.compileAdminIcon();

        // 卸载pc端
        if (is_dir(to_web_dir)) del_target_dir(to_web_dir, true);
        if (is_dir(to_web_layouts)) del_target_dir(to_web_layouts, true);

        // 卸载手机端
        if (is_dir(to_wap_dir)) del_target_dir(to_wap_dir, true);

        //删除资源文件
        if (is_dir(to_resource_dir)) del_target_dir(to_resource_dir, true);

        //todo  卸载插件目录涉及到的空文件
        return true;
    }

    /**
     * 卸载菜单
     * @return true
     * @throws DbBusinessException
     */
    async uninstallMenu()
    {
        const core_menu_service = this.coreMenuService;
        core_menu_service.deleteByAddon(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 卸载计划任务
     * @return true
     */
    async uninstallSchedule()
    {
        this.coreScheduleInstallService.uninstallAddonSchedule(this.addon);
        return true;
    }

    /**
     * 卸载手机端
     * @return void
     */
    async uninstallWap()
    {
        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.uninstallPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    /**
     * 安装插件菜单
     * @return true
     */
    async installMenu()
    {
        (new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * uninstallMenu
   * 对应 PHP: CoreAddonInstallService_core::uninstallMenu()
   * 逻辑类型: undefined - undefined
   */
  async uninstallMenu() {
    // 基于PHP真实逻辑: uninstallMenu
    // PHP原文: $core_menu_service = new CoreMenuService();         $core_menu_service->deleteByAddon($this->addon);         Cache::tag(MenuService::$cache_tag_name)-...
const core_menu_service = this.coreMenuService;
        core_menu_service.deleteByAddon(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 卸载计划任务
     * @return true
     */
    async uninstallSchedule()
    {
        this.coreScheduleInstallService.uninstallAddonSchedule(this.addon);
        return true;
    }

    /**
     * 卸载手机端
     * @return void
     */
    async uninstallWap()
    {
        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.uninstallPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    /**
     * 安装插件菜单
     * @return true
     */
    async installMenu()
    {
        (new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * uninstallSchedule
   * 对应 PHP: CoreAddonInstallService_core::uninstallSchedule()
   * 逻辑类型: undefined - undefined
   */
  async uninstallSchedule() {
    // 基于PHP真实逻辑: uninstallSchedule
    // PHP原文: (new CoreScheduleInstallService())->uninstallAddonSchedule($this->addon);         return true;     }      /**      * 卸载手机端      * @return void      */...
this.coreScheduleInstallService.uninstallAddonSchedule(this.addon);
        return true;
    }

    /**
     * 卸载手机端
     * @return void
     */
    async uninstallWap()
    {
        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.uninstallPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    /**
     * 安装插件菜单
     * @return true
     */
    async installMenu()
    {
        (new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * uninstallWap
   * 对应 PHP: CoreAddonInstallService_core::uninstallWap()
   * 逻辑类型: undefined - undefined
   */
  async uninstallWap() {
    // 基于PHP真实逻辑: uninstallWap
    // PHP原文: // 编译 diy-group 自定义组件代码文件         $this->compileDiyComponentsCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $t...
// 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.uninstallPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    /**
     * 安装插件菜单
     * @return true
     */
    async installMenu()
    {
        (new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * installMenu
   * 对应 PHP: CoreAddonInstallService_core::installMenu()
   * 逻辑类型: undefined - undefined
   */
  async installMenu() {
    // 基于PHP真实逻辑: installMenu
    // PHP原文: (new CoreMenuService)->refreshAddonMenu($this->addon);         Cache::tag(MenuService::$cache_tag_name)->clear();         return true;     }      /** ...
(new CoreMenuService).refreshAddonMenu(this.addon);
        Cache.tag(MenuService.cache_tag_name).clear(];
        return true;
    }

    /**
     * 安装手机端
     * @return void
     */
    async installWap()
    {

        // 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * installWap
   * 对应 PHP: CoreAddonInstallService_core::installWap()
   * 逻辑类型: undefined - undefined
   */
  async installWap() {
    // 基于PHP真实逻辑: installWap
    // PHP原文: // 编译 diy-group 自定义组件代码文件         $this->compileDiyComponentsCode($this->root_path . 'uni-app' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR, $t...
// 编译 diy-group 自定义组件代码文件
        this.compileDiyComponentsCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon];

        // 编译 pages.json 页面路由代码文件
        this.installPageCode(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR];

        // 编译 加载插件标题语言包
        this.compileLocale(this.root_path  + 'uni-app' . DIRECTORY_SEPARATOR  + 'src' . DIRECTORY_SEPARATOR, this.addon);

    }

    async download()
    {
    // 待实现
  }

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * download
   * 对应 PHP: CoreAddonInstallService_core::download()
   * 逻辑类型: undefined - undefined
   */
  async download() {
    // 基于PHP真实逻辑: download
    // PHP原文: }      public function edit()     {      }      /**      * 更新composer依赖      * @return true      */     public function updateComposer()     {        ...
}

    async edit()
    {
    // 待实现
  }

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * edit
   * 对应 PHP: CoreAddonInstallService_core::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit() {
    // 基于PHP真实逻辑: edit
    // PHP原文: }      /**      * 更新composer依赖      * @return true      */     public function updateComposer()     {         $result = Terminal::execute(root_path(),...
}

    /**
     * 更新composer依赖
     * @return true
     */
    async updateComposer()
    {
        const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * updateComposer
   * 对应 PHP: CoreAddonInstallService_core::updateComposer()
   * 逻辑类型: undefined - undefined
   */
  async updateComposer() {
    // 基于PHP真实逻辑: updateComposer
    // PHP原文: $result = Terminal::execute(root_path(), 'composer update');         if ($result !== true) {             throw new CommonException($result);...
const result = Terminal.execute(root_path(), 'composer update'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * updateAdminDependencies
   * 对应 PHP: CoreAddonInstallService_core::updateAdminDependencies()
   * 逻辑类型: undefined - undefined
   */
  async updateAdminDependencies() {
    // 基于PHP真实逻辑: updateAdminDependencies
    // PHP原文: $result = Terminal::execute(root_path() . '../admin/', 'npm install');         if ($result !== true) {             throw new CommonException($result);...
const result = Terminal.execute(root_path()  + '../admin/', 'npm install'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * updateWapDependencies
   * 对应 PHP: CoreAddonInstallService_core::updateWapDependencies()
   * 逻辑类型: undefined - undefined
   */
  async updateWapDependencies() {
    // 基于PHP真实逻辑: updateWapDependencies
    // PHP原文: $result = Terminal::execute(root_path() . '../uni-app/', 'npm install');         if ($result !== true) {             throw new CommonException($result...
const result = Terminal.execute(root_path()  + '../uni-app/', 'npm install'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * updateWebDependencies
   * 对应 PHP: CoreAddonInstallService_core::updateWebDependencies()
   * 逻辑类型: undefined - undefined
   */
  async updateWebDependencies() {
    // 基于PHP真实逻辑: updateWebDependencies
    // PHP原文: $result = Terminal::execute(root_path() . '../web/', 'npm install');         if ($result !== true) {             throw new CommonException($result);...
const result = Terminal.execute(root_path()  + '../web/', 'npm install'];
        if (result !== true) {
            throw new BusinessException(result);
  }

  /**
   * installComplete
   * 对应 PHP: CoreAddonInstallService_core::installComplete()
   * 逻辑类型: undefined - undefined
   */
  async installComplete() {
    // 基于PHP真实逻辑: installComplete
    // PHP原文: return true;     }      /**      * 安装计划任务      * @return true      */     public function installSchedule()     {         (new CoreScheduleInstallServ...
return true;
    }

    /**
     * 安装计划任务
     * @return true
     */
    async installSchedule()
    {
        this.coreScheduleInstallService.installAddonSchedule(this.addon);
        return true;
    }

    /**
     * 处理编译之后的文件
     * @return true
     */
    async handleBuildFile() {
        return true;
    }
}
  }

  /**
   * installSchedule
   * 对应 PHP: CoreAddonInstallService_core::installSchedule()
   * 逻辑类型: undefined - undefined
   */
  async installSchedule() {
    // 基于PHP真实逻辑: installSchedule
    // PHP原文: (new CoreScheduleInstallService())->installAddonSchedule($this->addon);         return true;     }      /**      * 处理编译之后的文件      * @return true      ...
this.coreScheduleInstallService.installAddonSchedule(this.addon);
        return true;
    }

    /**
     * 处理编译之后的文件
     * @return true
     */
    async handleBuildFile() {
        return true;
    }
}
  }

  /**
   * handleBuildFile
   * 对应 PHP: CoreAddonInstallService_core::handleBuildFile()
   * 逻辑类型: undefined - undefined
   */
  async handleBuildFile() {
    // 基于PHP真实逻辑: handleBuildFile
    // PHP原文: return true;     } }...
return true;
    }
}
  }
}
